OnlineAccount.isInstance   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
var GedcomX = require('../'),
2
    utils = require('../utils');
3
4
/**
5
 * An online account for a web application.
6
 * 
7
 * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#online-account|GEDCOM X JSON Spec}
8
 * 
9
 * @class
10
 * @extends ExtensibleData
11
 * @param {Object} [json]
12
 */
13
var OnlineAccount = function(json){
14
  
15
  // Protect against forgetting the new keyword when calling the constructor
16
  if(!(this instanceof OnlineAccount)){
17
    return new OnlineAccount(json);
18
  }
19
  
20
  // If the given object is already an instance then just return it. DON'T copy it.
21
  if(OnlineAccount.isInstance(json)){
22
    return json;
23
  }
24
  
25
  this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
26
};
27
28
OnlineAccount.prototype = Object.create(GedcomX.ExtensibleData.prototype);
29
30
OnlineAccount._gedxClass = OnlineAccount.prototype._gedxClass = 'GedcomX.OnlineAccount';
31
32
OnlineAccount.jsonProps = [
33
  'serviceHomepage',
34
  'accountName'
35
];
36
37
/**
38
 * Check whether the given object is an instance of this class.
39
 * 
40
 * @param {Object} obj
41
 * @returns {Boolean}
42
 */
43
OnlineAccount.isInstance = function(obj){
44
  return utils.isInstance(obj, this._gedxClass);
45
};
46
47
/**
48
 * Initialize from JSON
49
 * 
50
 * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
51
 * @return {OnlineAccount} this
52
 */
53
OnlineAccount.prototype.init = function(json){
54
  
55
  GedcomX.ExtensibleData.prototype.init.call(this, json);
56
  
57
  if(json){
58
    this.setAccountName(json.accountName);
59
    this.setServiceHomepage(json.serviceHomepage);
60
  }
61
  return this;
62
};
63
64
/**
65
 * Get the service home page
66
 * 
67
 * @returns {ResourceReference}
68
 */
69
OnlineAccount.prototype.getServiceHomepage = function(){
70
  return this.serviceHomepage;
71
};
72
73
/**
74
 * Set the service home page
75
 * 
76
 * @param {ResourceReference} serviceHomepage
77
 * @returns {OnlineAccount}
78
 */
79
OnlineAccount.prototype.setServiceHomepage = function(serviceHomepage){
80
  if(serviceHomepage){
81
    this.serviceHomepage = GedcomX.ResourceReference(serviceHomepage);
82
  }
83
  return this;
84
};
85
86
/**
87
 * Get the account name
88
 * 
89
 * @return {String}
90
 */
91
OnlineAccount.prototype.getAccountName = function(){
92
  return this.accountName;
93
};
94
95
/**
96
 * Set the account name
97
 * 
98
 * @param {String} accountName
99
 * @returns {OnlineAccount}
100
 */
101
OnlineAccount.prototype.setAccountName = function(accountName){
102
  this.accountName = accountName;
103
  return this;
104
};
105
106
/**
107
 * Export the object as JSON
108
 * 
109
 * @return {Object} JSON object
110
 */
111
OnlineAccount.prototype.toJSON = function(){
112
  return this._toJSON(GedcomX.ExtensibleData, OnlineAccount.jsonProps);
113
};
114
115
module.exports = OnlineAccount;